package com.aischool.webapp.family;

import java.util.Date;

import com.aischool.params.AiLifePiceseParams;
import com.aischool.routes.RouteMapping;
import com.aischool.service.AiLifePiceseService;
import com.aischool.service.AiStudentService;
import com.aischool.utils.AppUtil;
import com.aischool.utils.JsonCodeEnum;
import com.aischool.utils.JsonResult;
import com.jfinal.aop.Inject;

@RouteMapping(url = "/front/family/album")
public class AlbumController extends BaseFamilyController {

	@Inject
	AiLifePiceseService aiLifePiceseService;
	@Inject
	AiStudentService aiStudentService;
	
	/**
	 * 首页
	 */
	public void index() {
		render(view_path + "/album.html");
	}
	
	public void getAlbum() {
		// 结果类
		JsonResult jr = new JsonResult();
		// 参数类
		AiLifePiceseParams params = new AiLifePiceseParams();
		
		// 获取参数
		int login_org_id = this.getAttrForInt("login_org_id");	
		int login_class_id = this.getAttrForInt("login_class_id");		
		int type_id = getParaToInt("typeid",0);
		
		int page_no = getInt("pageNo", 1);
		int page_size = getInt("pageSize", AppUtil.Default_PageSize);
		
		Date start_date = getDate("start_date");
		Date end_date = getDate("end_date");
		
		params.setPageNo(page_no);
		params.setPageSize(page_size);
		
		params.setTypeId(type_id);
		params.setUserId(login_org_id);
		params.setClassId(login_class_id);
		
		params.setStudentId(getInt("stuid", 0));
		
		params.setReadPower(1); // 1 公开
		params.setState(1);
		params.setIsTimeLine(true);
		params.setStartDate(start_date);
		params.setEndDate(end_date);
		
		if (page_no == 1 && params.getStudentId() > 0) {
			Object obj = aiStudentService.getOne(params.getStudentId());
			jr.setDicKV("student_rd", obj);
		}

		// 获取分页
		Object pageData = aiLifePiceseService.getPage(params);
		
		jr.setDicKV("pageData", pageData);
		
		
		jr.setEnum(JsonCodeEnum.Success);
		renderJson(jr.Dic);
	}
}
